export default `import { defineComponent, ref, inject } from 'vue'
import { useFullscreen } from '@vueuse/core'
import type { FormInst, FormRules, FormItemRule } from 'naive-ui'
import { NButton, useMessage, NModal, NForm, NFormItem, NInput } from 'naive-ui'
import dyFormApi from '@/service/api/dyForm'
import MacHeader from '@/components/codeBlock/MacHeader'
export default defineComponent({
    emits: ['success'],
      setup(props, { emit, expose }) {
        const $clone = inject('$clone') as ${getT()}(data: T) => T
        const modalRef = ref()
        const { isFullscreen, toggle } = useFullscreen(modalRef)
        const show = ref(false)
        const title = ref('添加')
        const toast = useMessage()
        const queryForm: any = ref($t('queryForm'))
        const formRef = ref${getFormInst()}(null)
        const rules: FormRules = $t('rules')
        const handleValidateClick = (e: MouseEvent) => {
          e.preventDefault()
          formRef.value?.validate(errors => {
            if (!errors) {
              save()
            }
          })
        }
        const save = async () => {
            const params = $clone(queryForm.value)
            if (params?.id) {
              const { code, message } = await dyFormApi.edit(params)
              if (code !== 200) {
                toast.error(message)
                return
              }
              toast.success('编辑成功')
            } else {
              const { code, message } = await dyFormApi.add(params)
              if (code !== 200) {
                toast.error(message)
                return
              }
              toast.success('添加成功')
            }
            emit('success')
            close()
        }
        const close = () => {
          queryForm.value = $t('queryForm')
          show.value = false
        }
        const open = (row?: any) => {
          title.value = '添加'
          if (row) {
            const params: any = $clone(row)
            queryForm.value = params
            title.value = row?.id ? '编辑' : '添加'
          }
          show.value = true
        }
        expose({
          open
        })
         return () => (
          <NModal show={show.value} onUpdateShow={close}>
            <div ref={modalRef} class={pageStyle.modalEdit}>
                <MacHeader
                  title={title.value}
                  is-fullscreen={isFullscreen.value}
                  show-desc={false}
                  onToggle={toggle}
                  onClose={close}
                />
                <div class="content">
                   <NForm ref={formRef} model={queryForm.value} rules={rules}>
                     <NFormItem>
                        <div class="w-full flex justify-end">
                          <NButton type="primary" attr-type="button" onClick={handleValidateClick}>
                            <span>提交</span>
                          </NButton>
                        </div>
                      </NFormItem>
                   </NForm>
                </div>                 
            </div>
          </NModal>
         )
      })
})
`
function getT() {
  return '<' + 'T' + '>'
}

function getFormInst() {
  return '<' + 'FormInst | null' + '>'
}
